package ni;

import cont.*;
import java.io.IOException;
import commProtocol.*;
import java.net.SocketException;
public class ChatNI implements Observer_udp{

    String localHost;
    private ClassUDP udp;
    private ClassTCP tcp;
    private ChatController controller;

    public String getAdresse_locale(){
        return this.localHost;
    }

    public void send_multi(Message message) throws Exception{
        udp.SendHelloBye(message);
    }

    public void send(Message message, Contact contact) throws IOException, Exception{
        if (message instanceof Fichier){
           tcp.addCommunicationTCP(contact.getIp(), message);
        }
    }

    public void update(Message m){
        if (m instanceof Hello)
            controller.connexionContact(m.getSource());
        else if (m instanceof Bye)
            controller.connexionContact(m.getSource());
        else if(m instanceof Texte)
            controller.reception_message(m);
        else if (m instanceof Fichier)
            controller.reception_fichier(m);
        else System.out.println("Problème type du message reçu");
    }

    public ChatNI () throws SocketException, IOException{
        udp = new ClassUDP();
        tcp = new ClassTCP();

        udp.addObserver(this);
    }

}
